package com.pauldada.sakurabbs.controllers;

import com.pauldada.sakurabbs.entities.UserNow;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class SessionController {
    private static final String user_session="user_session";

    @GetMapping( "/hello")
    public String hello(){
        return "hello";
    }

    @GetMapping("/setSession")
    public Boolean setSession(HttpSession session){
        session.setAttribute(user_session,new UserNow(1L,"Paul"));
        return Boolean.TRUE;
    }

    @GetMapping("/getSession")
    public UserNow getSession(HttpSession session){
        return (UserNow)session.getAttribute(user_session);
    }

    @GetMapping("/invalidate")
    public Boolean invalidate(HttpSession session){
        session.invalidate();
        return Boolean.TRUE;
    }
}
